package com.chuan.jms.producer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

import javax.annotation.Resource;
import javax.jms.*;

/**
 * Created by zhaowenchuan on 2018/10/18.
 */
public class ProductorServiceImpl implements ProductorService {

    @Autowired
    JmsTemplate jmsTemplate;

    @Resource(name = "queueDestination")
    //@Resource(name = "topicDestination")   //主题模式
    Destination destination;

    @Override
    public void sendMessage(final String str) {
        jmsTemplate.send(new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                TextMessage textMessage = session.createTextMessage(str);
                System.out.println("发送成功" + textMessage.getText());
                return textMessage;
            }
        });
    }
}
